<?php

namespace PhpYes\Modules\Log\Example;


use PhpYes\Modules\Log\LogLevel;
use PhpYes\Modules\Log\LogRecordBase;

class ExampleLogRecord extends LogRecordBase
{

    private $host;
    private $file;
    private $line;


    /**
     * get 最终日志内容
     * @return string
     */
    public function getLogMessage()
    {
        $dt = $this->dt ? $this->dt : new \DateTime();

        return json_decode(array(
            'time' => $dt->format('Y-m-d H:i:s'),
            'level' => empty($this->level) ? LogLevel::ERROR : $this->level,
            'host' => empty($this->host) ? gethostname() : $this->host,
            'file' => empty($this->file) ? '' : $this->file,
            'line' => empty($this->line) ? '' : $this->line,
            'msg' => empty($this->message) ? '' : $this->message,
        ));
    }

    /**
     * @param string $level - refer LogLevel
     * @param string $message
     * @return void
     */
    public function log($level, $message)
    {
        $this->level = $level;
        $this->message = $message;
        $this->host = gethostname();
        $this->file = __FILE__;
        $this->line = __LINE__;
    }
}